From d276cd47a5db26718f03b84ca3586a4fc5475f1b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Sun, 12 Mar 2017 18:36:21 +0000 Subject: [PATCH] meson: tests: make tests find resources from the source dir Should probably also do this in the autotools build, since the same problem exists there as well if we use srcdir != builddir. --- tests/meson.build | 10 +++++++--- tests/testdialog.c | 5 +++++ tests/testgiconpixbuf.c | 5 +++++ tests/testgtk.c | 6 ++++++ tests/testiconview.c | 5 +++++ tests/testpopover.c | 5 +++++ tests/testselectionmode.c | 5 +++++ tests/testsplitheaders.c | 5 +++++ tests/teststackedheaders.c | 5 +++++ 9 files changed, 48 insertions(+), 3 deletions(-) diff --git a/tests/meson.build b/tests/meson.build index 34bd68aff0..2435e3d0e4 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -137,12 +137,16 @@ if x11_enabled gtk_tests += [['testerrors']] endif -# TODO: need to pass source dir so progs can find .ui files and such -# (with autotools this only works in the builddir == srcdir case) +# Pass the source dir here so programs can change into the source directory +# and find .ui files and .png files and such that they load at runtime +test_args = ['-DGTK_SRCDIR="@0@"'.format(meson.current_source_dir())] + foreach t : gtk_tests test_name = t.get(0) test_srcs = ['@0@.c'.format(test_name), t.get(1, [])] - executable(test_name, test_srcs, dependencies: [libgtk_dep, libm]) + executable(test_name, test_srcs, + c_args : test_args, + dependencies : [libgtk_dep, libm]) endforeach subdir('visuals') diff --git a/tests/testdialog.c b/tests/testdialog.c index 941acfdba1..07eba4b7b9 100644 --- a/tests/testdialog.c +++ b/tests/testdialog.c @@ -1,4 +1,5 @@ #include +#include static void show_message_dialog1 (GtkWindow *parent) @@ -316,6 +317,10 @@ main (int argc, char *argv[]) GtkWidget *box; GtkWidget *button; +#ifdef GTK_SRCDIR + g_chdir (GTK_SRCDIR); +#endif + gtk_init (); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); diff --git a/tests/testgiconpixbuf.c b/tests/testgiconpixbuf.c index 8e9b7af587..fd9ab1d558 100644 --- a/tests/testgiconpixbuf.c +++ b/tests/testgiconpixbuf.c @@ -17,6 +17,7 @@ */ #include +#include int main (int argc, @@ -28,6 +29,10 @@ main (int argc, GEmblem *emblem; gchar *str; +#ifdef GTK_SRCDIR + g_chdir (GTK_SRCDIR); +#endif + gtk_init (); pixbuf = gdk_pixbuf_new_from_file ("apple-red.png", NULL); diff --git a/tests/testgtk.c b/tests/testgtk.c index 082ea55e0b..93f8c96928 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -37,6 +37,8 @@ #include #endif +#include + #include "gtk/gtk.h" #include "gdk/gdk.h" #include "gdk/gdkkeysyms.h" @@ -8805,6 +8807,10 @@ main (int argc, char *argv[]) g_set_application_name ("GTK+ Test Program"); +#ifdef GTK_SRCDIR + g_chdir (GTK_SRCDIR); +#endif + gtk_init (); provider = gtk_css_provider_new (); diff --git a/tests/testiconview.c b/tests/testiconview.c index 0a89fa6a5b..c35916cc7d 100644 --- a/tests/testiconview.c +++ b/tests/testiconview.c @@ -16,6 +16,7 @@ */ #include +#include #include #include @@ -420,6 +421,10 @@ main (gint argc, gchar **argv) GtkCellRenderer *cell; GtkTreeViewColumn *tvc; +#ifdef GTK_SRCDIR + g_chdir (GTK_SRCDIR); +#endif + gtk_init (); /* to test rtl layout, set RTL=1 in the environment */ diff --git a/tests/testpopover.c b/tests/testpopover.c index 6d12d6c8ac..da5839de1c 100644 --- a/tests/testpopover.c +++ b/tests/testpopover.c @@ -1,4 +1,5 @@ #include +#include static void activate (GSimpleAction *action, @@ -48,6 +49,10 @@ main (int argc, char *argv[]) GtkWidget *check; GtkWidget *combo; +#ifdef GTK_SRCDIR + g_chdir (GTK_SRCDIR); +#endif + gtk_init (); win = gtk_window_new (GTK_WINDOW_TOPLEVEL); diff --git a/tests/testselectionmode.c b/tests/testselectionmode.c index c639bbe8eb..f3b983f912 100644 --- a/tests/testselectionmode.c +++ b/tests/testselectionmode.c @@ -1,4 +1,5 @@ #include +#include typedef struct { GtkListBoxRow parent; @@ -179,6 +180,10 @@ main (int argc, char *argv[]) GSimpleActionGroup *group; GSimpleAction *action; +#ifdef GTK_SRCDIR + g_chdir (GTK_SRCDIR); +#endif + gtk_init (); builder = gtk_builder_new_from_file ("selectionmode.ui"); diff --git a/tests/testsplitheaders.c b/tests/testsplitheaders.c index 42de06d74f..7d89418886 100644 --- a/tests/testsplitheaders.c +++ b/tests/testsplitheaders.c @@ -1,4 +1,5 @@ #include +#include static void split_decorations (GtkSettings *settings, @@ -42,6 +43,10 @@ main (int argc, char *argv[]) GtkWidget *check; GtkWidget *header; +#ifdef GTK_SRCDIR + g_chdir (GTK_SRCDIR); +#endif + gtk_init (); builder = gtk_builder_new_from_file ("testsplitheaders.ui"); diff --git a/tests/teststackedheaders.c b/tests/teststackedheaders.c index 830e9da761..c342d685ca 100644 --- a/tests/teststackedheaders.c +++ b/tests/teststackedheaders.c @@ -1,4 +1,5 @@ #include +#include static GtkWidget *header_stack; static GtkWidget *page_stack; @@ -23,6 +24,10 @@ main (int argc, char *argv[]) GtkBuilder *builder; GtkWidget *win; +#ifdef GTK_SRCDIR + g_chdir (GTK_SRCDIR); +#endif + gtk_init (); builder = gtk_builder_new (); -- 2.30.2